package edu.tapestry.iddb.client.pages.userIM;

import iddb.AbstractResponse;
import iddb.OkResponse;

import org.apache.tapestry5.annotations.ApplicationState;
import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;

import edu.tapestry.iddb.client.entities.UserIM;
import edu.tapestry.iddb.client.pages.ErrorPage;
import edu.tapestry.iddb.client.pages.OKPage;
import edu.tapestry.iddb.client.webService.CommandsGenerator;
import edu.tapestry.iddb.client.webService.IDDBProxy;

public class AddUserIM {

	@Persist
	@Property
	private UserIM userIM;

	@ApplicationState
	private IDDBProxy proxy;

	@InjectPage
	private ErrorPage error;

	@InjectPage
	private OKPage ok;

	Object onActionFromAdd() {

		AbstractResponse resp = proxy.execute(CommandsGenerator
				.createAddIMUser(userIM.getUsername(), userIM.getPasswd(),
						userIM.getType(), userIM.getSrvAddr(), userIM
								.getSrvPort(), userIM.getProfilname(), userIM
								.getPresence(), userIM.getOperation()));

		if (resp instanceof OkResponse) {
			return ok;
		} else {
			return error.initialize(resp);
		}
	}

}
